<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户的管理页面</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/default/easyui.css">   
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/themes/icon.css">  
<script src="<%=request.getContextPath() %>/js/jquery-1.11.2.min.js"></script> 
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.easyui.min.js"></script> 
</head>
<body>
	 <table id="datagrids"></table>   

<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
 <div id="dialogs" class="easyui-dialog" title="用户修改" style="width:400px;height:300px;"   
        data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true,buttons:'#bf'">   
     <div id="dds">    
   	 <form id="foe" action="">
   		<table>
   			<tr>
   				<td><input type="hidden" name="uid"></td>
   			</tr>
   			<tr>
   				<td>用户名称：</td>
   				<td><input type="text" name="username"></td>
   			</tr>
   			<tr>
   				<td>用户密码：</td>
   				<td><input type="text" name="password"></td>
   			</tr>

   			<tr>
   				<td>真实名称：</td>
   				<td><input type="text" name="name"></td>
   			</tr>
   			<tr>
   				<td>邮件：</td>
   				<td><input type="text" name="email"></td>
   			</tr>
   			<tr>
   				<td>电话：</td>
   				<td><input type="text" name="phone"></td>
   			</tr>
   			
   			<tr>
   				<td>地址：</td>
   				<td><input type="text" name="addr"></td>
   			</tr>
   			<tr>
   				<td>激活状态：</td>
   				<td><input type="text" name="state"></td>
   			</tr>
   			<tr>
   				<td><input type="submit" value="提交"></td>
   			</tr>
   		</table>
   		
   	</form> 
   </div>     
</div> 

<!-- 按钮   -->
<div id="bf">
			<a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">添加</a>  
			<a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a>	  
</div>

<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->


<script type="text/javascript">
	$("#datagrids").datagrid({
		url:"<%=request.getContextPath() %>/user/getUserList",
		columns:[[    
               {field:'uid',title:'用户ID',width:100},    
               {field:'username',title:'用户名称',width:100}, 
               {field:'password',title:'用户密码',width:100},
               {field:'name',title:'真实名称',width:100},
               {field:'email',title:'邮件',width:100},
               {field:'phone',title:'电话',width:100},
               {field:'addr',title:'地址',width:100},
               {field:'state',title:'激活状态',width:100},
		           ]],
	             fitColumns:true,
	             singleSelect:true,
	             pagination:true,
	 			pageSize:25,
	 			pageList:[25,50,75,100,125],
	 			toolbar: [{
	 				iconCls: 'icon-edit',
	 				handler: function(){
	 				//修改用户
	 					
	 					var row = $("#datagrids").datagrid("getSelected");
						if(row!=null){
							$("#dialogs").dialog('open');
							//数据的辉县
							$("#foe").form('load',row);
							//打开dialog
							$("#dialogs").dialog('open');
							//转换表单提交为ajax的提交
							$('#foe').form({    
				   				 url:"<%=request.getContextPath() %>/user/updateUser",    
				  				  onSubmit: function(){    
				  					 //首先加载，返回验证
				  					  return $("#foe").form('validate');    
						   		 },    
						    success:function(obj){    
						    	if(obj==1){
						    		//加强版弹框
									$.messager.alert("系统提示","修改成功");
									//关闭dialog
						    		$("#dialogs").dialog("close");
									//刷新datagrid
									$("#datagrids").datagrid("reload");
								}else{
									$.messager.alert("系统提示","修改失败");
								}    
						    }    
						});   
							
						}else{
							$.messager.alert("系统提示","请选择一行");
						}		
	 				}
	 			},'-',{
	 				iconCls: 'icon-remove',
	 				handler: function(){
	 				//删除用户
	 				var row=$("#datagrids").datagrid('getSelected');
	 					alert(row.uid);
	 					if(row!=null){
	 						//如果选中一行则执行删除
	 						$.ajax({
	 							url:"<%=request.getContextPath() %>/user/removeUser",
	 							type:"post",
	 							data:{uid:row.uid},
	 							success:function(obj){
	 								if(obj==1){
							    		//加强版弹框
										$.messager.alert("系统提示","删除成功");
										
										$("#datagrids").datagrid("reload");
									}else{
										$.messager.alert("系统提示","修改失败");
									}   
	 								
	 							},
	 							dataType:"",
	 						});
	 						
	 						
	 					}else{
	 						$.messager.alert("系统提示","请选中一行进行删除");
	 					}
	 					
	 				}
	 			}]

		
		
	});


</script> 
</body>



</html>